<template>
  <el-button
    size="small"
    type="text"
    icon="Edit"
    @click="open"
    v-hasPermi="['system:reply:add']"
  >回复</el-button>
  <el-dialog title="反馈回复" v-model="visible" :destroy-on-close="true" width="500px" append-to-body>
    <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="反馈内容" prop="replyContent">
        <el-input v-model="form.replyContent" type="textarea" :autosize="{ minRows: 3 }" placeholder="请输入反馈回复" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submit">确 定</el-button>
      <el-button @click="visible = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script setup>
  import { ref } from 'vue';
  import { addReply } from "@/api/system/reply";
  import dayjs from 'dayjs';
  import { ElMessage } from 'element-plus';

  const props = defineProps({
    row: {
      type: Object,
    }
  });
  const emits = defineEmits(['success']);
  const visible = ref(false);
  const form = ref({});
  const formRef = ref();
  const rules = {
    replyContent: [{
      required: true, message: '请输入反馈回复'
    }]
  };
  const open = () => {
    visible.value = true;
    form.value = {
      feedbackId: props.row.id,
      replyContent: '',
    };
  }
  const submit = async () => {
    await formRef.value.validate();
    const res = await addReply({
      ...form.value,
      replyTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
    });
    emits('success');
    visible.value = false;
    ElMessage.success('回复成功')
  }
</script>

<style scoped>

</style>
